F77 = @FC@
GCC = @CC@
GXX = @CXX@
GFLAGS = @CPPFLAGS@
FFLAGS = @FCFLAGS@
BIN = ../bin
LDIR = -L../lib -L/opt/local/lib
LIBRARIES = ../lib/libgen.a ../lib/libmisc.a ../lib/libim2k.a ../lib/libplot2k.a ../lib/libfft.a ../lib/libconv.a ../lib/lib2dx.a
LFLAG = -l2dx -lim2k -lmisc -lgen -lplot2k -lfft -lconv -lfftw3f @LIBS@
SOURCES = $(wildcard *.for) $(wildcard *.c) $(patsubst Cspotarrays.cpp,,$(patsubst Creflectionsarray.cc,,$(wildcard *.cc)))
CSOURCES = Creflectionsarray.cc Cspotarrays.cpp
OBJECTS = $(patsubst %.cpp,%.o,$(patsubst %.cc,%.o,$(CSOURCES)))
BINARIES = $(patsubst %.cc,$(BIN)/%.exe,$(patsubst %.c,$(BIN)/%.exe,$(patsubst %.for,$(BIN)/%.exe,$(SOURCES)))) 
PEAKMAKE = cd ./peaksearch; make all; cd ..
GETLATMAKE = cd ./2dx_getlat; make all; cd ..
ENDIANMAKE = cd ./endianness; make all; cd ..
FOURIERCROPMAKE = cd ./fouriercrop; make all; cd ..
CTFMAKE = cd ./ctf; make all; cd ..
MOVIEMAKE = cd ./movie; make all; cd ..
SPMAKE = cd ./single-particle; make all; cd ..
PEAKMAKECLEAN = cd ./peaksearch; make clean; cd ..
GETLATMAKECLEAN = cd ./2dx_getlat; make clean; cd ..
ENDIANMAKECLEAN = cd ./endianness; make clean; cd ..
FOUIERCROPMAKECLEAN = cd ./fouriercrop; make clean; cd ..
CTFMAKECLEAN = cd ./ctf; make clean; cd ..
MOVIEMAKECLEAN = cd ./movie; make clean; cd ..
SPMAKECLEAN = cd ./single-particle; make clean; cd ..


all: $(LIBRARIES) $(BINARIES)

$(BIN)/%.exe: %.for 
	$(F77) $(FFLAGS) -o $@ $< $(LDIR) $(LFLAG)

$(BIN)/%.exe: %.cc
	$(GXX) $(GFLAGS) -o $@ $< $(CSOURCES) 

$(BIN)/%.exe: %.c
	$(GCC) $(GFLAGS) -o $@ $< 

$(PEAKSEARCH):  
	$(PEAKMAKE)	

$(GETLAT):  
	$(GETLATMAKE)	

$(ENDIAN):  
	$(ENDIANMAKE)	

$(CTF):  
	$(CTFMAKE)	

$(MOVIE):  
	$(MOVIEMAKE)	

$(SP):  
	$(SPMAKE)	
clean:
	\rm -f $(BINARIES) $(OBJECTS);
	$(PEAKMAKECLEAN)
	$(GETLATMAKECLEAN)
	$(ENDIANMAKECLEAN)
	$(FOURIERCROPMAKECLEAN)
	$(CTFMAKECLEAN)
	$(MOVIEMAKECLEAN)

# 	$(SPMAKECLEAN) 

